from one.Day6.mysql import Mysql
import unittest,requests


class Login(unittest.TestCase):

    def setUp(self):
        self.a = Mysql('10.59.9.14', 'root', 'yidong666', 3306, 'a3mall')

    # 登录
    def test_01_login(self):
        url = 'http://10.59.9.14:7003/api/public/login'
        json = {"username": "17733058407","password": "li123456"}
        login = requests.post(url=url,json=json)
        print(login.json())
        username = login.json()['data']['username']
        print(username)

        o= self.a.search_sql(f"select username from mall_users where username='{username}'")
        self.assertEqual(username,o[0][0])

    def test_02_detail(self):
        url = 'http://10.59.9.14:7003/api/goods/view?id=40'
        detail = requests.get(url=url)
        print(detail.json())
        title = detail.json()['data']['goods']['title']
        print(title)
        o = self.a.search_sql(f"select title from mall_goods where title='{title}'")
        self.assertEqual(title,o[0][0])


    def tearDown(self):
        self.a.close()


if __name__ == '__main__':
    unittest.main()
